#ifdef WIN32
#include <windows.h>
#endif

#include "tank.h"
#include <cstdlib>
#include <GL/gl.h>

using namespace bend2d;

Tank::Tank(const Point& position) : 
    Box(bend2d::Rectangle(position, Angle(0), 40, 30)),
    m_FireEngine(NULL)
{
    
    SetPosition(position);
    m_FireEngine = new TankFireEngine(position);
}

void Tank::Draw()
{
     glPushMatrix();
     glLineWidth(1.0);
     glColor3d(m_TankColor.GetRedFloat(), m_TankColor.GetGreenFloat(), m_TankColor.GetBlueFloat());
     
     const bend2d::Rectangle& rectangle = GetRectangle();
     glTranslated(rectangle.GetCenter().GetX(), rectangle.GetCenter().GetY(), 0);
     glRotated(GetAngle().GetAngle(), 0, 0, 1);
     
     glBegin(GL_POLYGON);
         glVertex2d(rectangle.GetAbsLeft(), rectangle.GetAbsTop());
         glVertex2d(rectangle.GetAbsRight(), rectangle.GetAbsTop());
         glVertex2d(rectangle.GetAbsRight(), rectangle.GetAbsBottom());
         glVertex2d(rectangle.GetAbsLeft(), rectangle.GetAbsBottom());
     glEnd();     
     
     glPopMatrix();
     
     m_FireEngine->SetPosition(GetPosition());
     m_FireEngine->Draw();
}
